package com.cmpe.av.androidservice;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cmpe.av.logic.ReportLogic;
import com.cmpe.av.model.Comment;

/**
 * Servlet implementation class AndroidComment
 */
@WebServlet("/AndroidComment")
public class AndroidComment extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AndroidComment() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try{
			ReportLogic msAccess = new ReportLogic();
			long userID = Long.parseLong(request.getParameter("userID"));
			long reportID = Long.parseLong(request.getParameter("reportID"));
			Comment comment = new Comment();
			comment.setReportId(reportID);
			comment.setText(request.getParameter("comment"));
			comment.setUserId(userID);
			msAccess.addComment(comment);
			response.getWriter().print("success");
		}catch(Exception e){
			e.printStackTrace();
			response.getWriter().print("error");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
